package com.hdy.javachatroomdemo.factory;

import com.hdy.javachatroomdemo.Enum.ResultCodeEnum;
import com.hdy.javachatroomdemo.constant.Constants;
import com.hdy.javachatroomdemo.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

@Component
public class MessageTransferFactory {
    @Autowired
//    private ConcurrentHashMap<String,IMessageTransfer> MessageTransferMap ;
    private ApplicationContext applicationContext;
    public IMessageTransfer getTransfer(String type){
        IMessageTransfer messageTransfer=applicationContext.getBean(type+ Constants.FACTORY_SUFFIX, IMessageTransfer.class);
       if(messageTransfer == null){
           throw new ServiceException(ResultCodeEnum.FAIL_TRANSFER_TYPE);
       }
       return messageTransfer;
    }
}
